package com.cms.jy.draft.entity;

import lombok.Data;

/**
 * 转场实体类
 */
@Data
public class Transition {
    /**
     * 转场名称
     */
    private String name;
    
    /**
     * 是否为VIP特权
     */
    private boolean is_vip;
    
    /**
     * 资源ID
     */
    private String resource_id;
    
    /**
     * 效果ID
     */
    private String effect_id;
    
    /**
     * MD5值
     */
    private String md5;
    
    /**
     * 默认持续时间, 单位为微秒
     */
    private long duration;
    
    /**
     * 是否允许重叠
     */
    private boolean is_overlap;
    
    // 保留现有字段以确保向后兼容性
    /**
     * 分类ID
     */
    private String category_id;
    
    /**
     * 分类名称
     */
    private String category_name;
    
    /**
     * ID
     */
    private String id;
    
    /**
     * 路径
     */
    private String path;
    
    /**
     * 平台
     */
    private String platform;
    
    /**
     * 请求ID
     */
    private String request_id;
    
    /**
     * 类型
     */
    private String type;
    
    /**
     * 设置是否重叠
     * @param isOverlap 是否重叠
     */
    public void setIs_overlap(boolean isOverlap) {
        this.is_overlap = isOverlap;
    }
    
    /**
     * 根据Python Transition_meta构造函数参数创建Transition对象
     * @param name 转场名称
     * @param isVip 是否为VIP特权
     * @param resourceId 资源ID
     * @param effectId 效果ID
     * @param md5 MD5值
     * @param defaultDuration 默认持续时间(秒)
     * @param isOverlap 是否允许重叠
     */
    public Transition(String name, boolean isVip, String resourceId, 
                      String effectId, String md5, double defaultDuration, 
                      boolean isOverlap) {
        this.name = name;
        this.is_vip = isVip;
        this.resource_id = resourceId;
        this.effect_id = effectId;
        this.md5 = md5;
        // 将秒转换为微秒
        this.duration = Math.round(defaultDuration * 1_000_000);
        this.is_overlap = isOverlap;
    }
    
    // 无参构造函数
    public Transition() {
    }

    public Transition setDuration(double duration) {
        this.duration = (long) (duration * 1000000);
        return this;
    }
}